package com.gzz.boot.repush;

import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate;

/**
 * 记录重推参数工具类
 */
@Slf4j
public class RePushUtil {

    private static IRePushService rePushService;

    /**
     * 记录重推参数
     * @param interfaceName 接口名称 (必传)
     * @param status 推送状态 0:未推送  1:已推送 (默认成功)
     * @param callbackMethod 回调方法
     * @param className 类名 Class.getName() (必传)
     * @param methodName 方法名 (必传)
     * @param params 方法参数
     */
    public static void saveReRushLog(String interfaceName, Integer status , Predicate<Object> callbackMethod, String className, String methodName, Object... params){
        CompletableFuture.runAsync(() -> {
            IRePushService iRePushService = getIRePushService();
            try {
                iRePushService.saveReRushLog(interfaceName,status,callbackMethod,className,methodName,params);
            } catch (Exception e) {
                log.error("记录重推参数异常:{}--{}",e.getMessage(), Arrays.toString(e.getStackTrace()));
            }
        });
    }

    public static IRePushService getIRePushService(){
        if(null == rePushService){
            // 从Spring容器中获取Bean
            // rePushService = SpringContextUtil.getBean(IRePushService.class);
        }
        return rePushService;
    }
}